#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include "lexical.h"
#include "syntaxCfree.h"
#include "syntaxDev.h"
#include "token.h"
#pragma warning(disable : 4996)
string getline()
{
	string str = string();
	char ch;
	while (ch = getchar(), ch == '\n');
	str = ch;
	while (ch = getchar(), ch != '\n')str += ch;
	return str;
}
int main(int argc,char*argv[])
{
	//SetConsoleTitle("C++ HighLight"); 
	string Input;
	string Output;
	string Name;
	int t=0,conmd=0;
	if(argc>=5)
	{
		conmd=1;
		if(strcmp(argv[1],"cfree")==0)
			t=1;
		else if(strcmp(argv[1],"devcpp")==0)
			t=0;
		else
		postErr("ERROR","style error(only devcpp or cfree)",conmd);
		Input = argv[2];
		Output = argv[3];
		Name = argv[4];
		goto here;
	}
	printf("Dev C++   \r");
	while(1)
	{
		int c=_getch();	
		if(c==32)break;
		if(c==13)break;
		if(c==224)
		{
			c=_getch();
			switch(c)
			{
				case 72:case 80:case 75:case 77:
				if(t==0)
				{
					t=1;
					printf("C Free5.0   \r");
				}else{
					t=0;
					printf("Dev C++   \r");
				}
			}
		}
	}
	printf("Input File(*.cpp):");
	Input = getline();
	printf("Output File(*.html):");
	Output = getline();
	puts("Name:");
	Name = getline();
	here:
	FILE *fi=fopen(Input.c_str(),"r"),*fo=fopen(Output.c_str(),"w");
	if((fi==NULL)||(fo==NULL))
		postErr("Warning","File io Failed.",conmd);
	RegistI(fi);
	RegistO(fo);
	RegistModel(t);
	if(t==1)
	system_goal_Cfree(Name);
	else
	system_goal_Dev(Name);
	return 0;
}
